<?php

namespace Admin\Model;

use Think\Model;

class TagModel extends Model {
	
	/**
	 * 添加数据
	 *
	 * @param unknown $data        	
	 * @return Ambigous <string, \Think\mixed, boolean, unknown>
	 */
	public function saveData($tagArr, $obj_id, $obj_type) {
		if (! tagArr) {
			$result ['status'] = 0;
			$result ['info'] = '标签不能空';
		} elseif (! $obj_type) {
			$result ['status'] = 0;
			$result ['info'] = '类型不能空';
		} elseif (! $obj_id) {
			$result ['status'] = 0;
			$result ['info'] = '对象ID不能空';
		} else {
			foreach ( $tagArr as $tag ) {
				$data = array ();
				$data ['name'] = $tag;
				$data ['obj_id'] = $obj_id;
				$data ['obj_type'] = $obj_type;
				$rs = $this->add ( $data );
			}
			if ($rs) {
				$result ['status'] = 1;
				$result ['info'] = '添加成功';
				$result ['id'] = $rs;
			} else {
				$result ['status'] = 0;
				$result ['info'] = '添加失败';
			}
		}
		return $result;
	}
	
	/**
	 * 删除操作
	 *
	 * @param unknown $obj_id        	
	 * @param unknown $obj_type        	
	 * @return number
	 */
	public function deleteDate($obj_id, $obj_type) {
		$where = "obj_id='{$obj_id}' and obj_type='{$obj_type}'";
		$rs = $this->where ( $where )->delete ();
		if ($rs) {
			$result ['msg'] = '删除成功';
			$result ['status'] = 1;
		} else {
			$result ['msg'] = '删除失败';
			$result ['status'] = 0;
		}
		return $result;
	}
}